package com.yanqu.road.dao.impl.activity.zhenhuan;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.zhenhuan.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class ZhenHuanImpl extends TempDao {
    private static String getZhenHuanStoryConfigSql = "select * from `t_s_activity_zhenhuan_story` where `activityId`=?";
    public Map<Integer, ZhenHuanStoryConfig> getZhenHuanStoryConfigMap(int activityId) {
        Map<Integer, ZhenHuanStoryConfig> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getZhenHuanStoryConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ZhenHuanStoryConfig data = new ZhenHuanStoryConfig(rs);
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public static String getZhenHuanConcubineConfigSql = "select * from `t_s_activity_zhenhuan_concubine` where `activityId`=?";
    public Map<Integer, ZhenHuanConcubineConfig> getZhenHuanConcubineConfigMap(int activityId) {
        Map<Integer, ZhenHuanConcubineConfig> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getZhenHuanConcubineConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ZhenHuanConcubineConfig data = new ZhenHuanConcubineConfig(rs);
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public static String getZhenHuanLevelConfigSql = "select * from `t_s_activity_zhenhuan_level` where `activityId`=?";
    public Map<Integer, ZhenHuanLevelConfig> getGetZhenHuanLevelConfigMap(int activityId) {
        Map<Integer, ZhenHuanLevelConfig> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getZhenHuanLevelConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ZhenHuanLevelConfig data = new ZhenHuanLevelConfig(rs);
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public static String getZhenHuanPlaceConfigSql = "select * from `t_s_activity_zhenhuan_place` where `activityId`=?";
    public Map<Integer, ZhenHuanPlaceConfig> getGetZhenHuanPlaceConfigMap(int activityId) {
        Map<Integer, ZhenHuanPlaceConfig> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getZhenHuanPlaceConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ZhenHuanPlaceConfig data = new ZhenHuanPlaceConfig(rs);
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public static String getZhenHuanTextConfigSql = "select * from `t_s_activity_zhenhuan_text` where `activityId`=?";
    public Map<Integer, ZhenHuanTextConfig> getGetZhenHuanTextConfigMap(int activityId) {
        Map<Integer, ZhenHuanTextConfig> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getZhenHuanTextConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ZhenHuanTextConfig data = new ZhenHuanTextConfig(rs);
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public static String getZhenHuanNpcConfigSql = "select * from `t_s_activity_zhenhuan_npc` where `activityId`=?";
    public Map<Integer, ZhenHuanNpcConfig> getGetZhenHuanNpcConfigMap(int activityId) {
        Map<Integer, ZhenHuanNpcConfig> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getZhenHuanNpcConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ZhenHuanNpcConfig data = new ZhenHuanNpcConfig(rs);
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

}
